package com.woniuxy.creditsystem.statisticsmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.MoneyChannelInfo;
import com.woniuxy.creditsystem.common.bean.UserConversionInfo;
import com.woniuxy.creditsystem.common.mapper.UserConversionMapper;
import com.woniuxy.creditsystem.statisticsmag.page.PageRequest;
import com.woniuxy.creditsystem.statisticsmag.service.IUserConversionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Transactional(readOnly = true)
@Service
public class UserConversionServiceImpl implements IUserConversionService {

    @Resource
    private UserConversionMapper userConversionMapper;

    /**
     * 分页查询前一日每个渠道的数据
     * @param request               分页的请求对象
     * @param userConversionInfo    分页条件
     * @return
     */
    @Override
    public PageInfo<UserConversionInfo> findAllByParams(PageRequest request, UserConversionInfo userConversionInfo) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->userConversionMapper.findAllByParams(request,userConversionInfo));
    }

    /**
     * 分页查询具体某一渠道用户转化统计表
     * @param request
     * @param userConversionInfo
     * @return
     */
    @Override
    public PageInfo<UserConversionInfo> findDefByParams(PageRequest request, UserConversionInfo userConversionInfo) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->userConversionMapper.findDefByParams(request,userConversionInfo));
    }

    @Override
    public UserConversionInfo findDefOne(UserConversionInfo userConversionInfo) {
        return userConversionMapper.findDefOne(userConversionInfo);
    }
    /**
     * 查询当日所有渠道的用户统计信息
     * @return
     */
    @Override
    public List<UserConversionInfo> findUser() {
        return userConversionMapper.findUser();
    }



    /**
     * 添加用户转化数据(定时任务)
     */
    @Override
    public void addUserCon() {
        //查询所有渠道
        List<MoneyChannelInfo> list1 = userConversionMapper.findChannel();
        for (MoneyChannelInfo mon : list1){
            //保存
            UserConversionInfo user = new UserConversionInfo();
            user.setChannel(mon.getDitchAllname());
            System.out.println("渠道名称:" + mon.getDitchAllname());
            System.out.println("注册用户数:" + userConversionMapper.findRegist(mon.getId()));
            System.out.println("提交审核数:" + userConversionMapper.findAudit(mon.getId()));
        }
    }
}
